package com.shu.validator;

import com.shu.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MyConstraintValidator implements ConstraintValidator<MyConstraint,Object> {

    @Autowired
    HelloService helloService;


    @Override
    public void initialize(MyConstraint myConstraint) {
        //校验器初始化的时候
        System.out.println("my validator init");
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        //校验逻辑
        System.out.println(o);
        String msg = helloService.greeting("小明");
        System.out.println(msg);
        return false;
    }
}
